﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;

namespace Dao
{
    static class DaoCustomer
    {
        public static void Add(Customer customer)
        {
            NorthwindEntities entities = new NorthwindEntities();
            using (entities)
            {
                entities.Customers.AddObject(customer);
                entities.SaveChanges();
            }
        }

        public static void Edit(Customer customer)
        {
            NorthwindEntities entities = new NorthwindEntities();
            using (entities)
            {
                entities.AttachTo("Customers",customer);
                entities.ObjectStateManager.GetObjectStateEntry(customer).SetModified();
                entities.Refresh(System.Data.Objects.RefreshMode.ClientWins, customer);
                entities.SaveChanges();
            }
        }

        public static void Delete(Customer customer)
        {
             NorthwindEntities entities = new NorthwindEntities();
             using (entities)
             {
                 entities.AttachTo("Customers",customer);
                 entities.Customers.DeleteObject(customer);
                 entities.SaveChanges();
             }
        }
    }
}
